/*
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * PlayerListPanel.java
 *
 * Created on May 1, 2009, 9:05:07 AM
 */
package hextd.UI;

import com.usoog.tdcore.UserInfo;
import hextd.Constants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

/**
 *
 * @author hylke
 */
public class PlayerListPanel extends javax.swing.JPanel {

	private boolean selected = false;
	private UserInfo info;
	private boolean longFormat = true;

	/** Creates new form PlayerListPanel */
	public PlayerListPanel() {
		initComponents();
	}

	public PlayerListPanel(UserInfo info) {
		initComponents();
		setInfo(info);
	}

	public final void setInfo(UserInfo info) {
		this.info = info;
		jLabelName.setText(info.name);
		jLabelRank.setText("" + info.rank);
		jLabelGames.setText("" + info.games);
		jLabelName.setForeground(Constants.getColorPlayer(info.playerId));
	}

	public UserInfo getInfo() {
		return info;
	}

	public void setSelected(boolean selected) {
		if (this.selected != selected) {
			this.selected = selected;
			if (selected) {
				this.setBorder(new LineBorder(Constants.colorForeGroundPale));
			} else {
				this.setBorder(new EmptyBorder(1, 1, 1, 1));
			}
		}
	}

	public boolean isLongFormat() {
		return longFormat;
	}

	public void setLongFormat(boolean longFormat) {
		if (this.longFormat != longFormat) {
			this.longFormat = longFormat;
			jLabelGames.setVisible(longFormat);
			jLabelRank.setVisible(longFormat);
		}
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabelName = new javax.swing.JLabel();
        jLabelRank = new javax.swing.JLabel();
        jLabelGames = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setBackground(Constants.colorBackGround);
        setForeground(Constants.colorForeGround);
        setLayout(new java.awt.GridBagLayout());

        jLabelName.setBackground(Constants.colorBackGround);
        jLabelName.setForeground(Constants.colorForeGround);
        jLabelName.setText("Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0E-6;
        add(jLabelName, gridBagConstraints);

        jLabelRank.setBackground(Constants.colorBackGround);
        jLabelRank.setFont(jLabelRank.getFont().deriveFont(jLabelRank.getFont().getSize()-2f));
        jLabelRank.setForeground(Constants.colorForeGround);
        jLabelRank.setText("1000");
        jLabelRank.setToolTipText("Rank on the multiplayer ladder");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        add(jLabelRank, gridBagConstraints);

        jLabelGames.setBackground(Constants.colorBackGround);
        jLabelGames.setFont(jLabelGames.getFont().deriveFont(jLabelGames.getFont().getSize()-2f));
        jLabelGames.setForeground(Constants.colorForeGround);
        jLabelGames.setText("-5");
        jLabelGames.setToolTipText("Number of ladder games played");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        add(jLabelGames, gridBagConstraints);

        jLabel1.setBackground(Constants.colorBackGround);
        jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getSize()-2f));
        jLabel1.setForeground(Constants.colorForeGround);
        jLabel1.setText("Games:");
        jLabel1.setToolTipText("Number of ladder games played");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0E-6;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
        add(jLabel1, gridBagConstraints);

        jLabel3.setBackground(Constants.colorBackGround);
        jLabel3.setFont(jLabel3.getFont().deriveFont(jLabel3.getFont().getSize()-2f));
        jLabel3.setForeground(Constants.colorForeGround);
        jLabel3.setText("Rank:");
        jLabel3.setToolTipText("Rank on the multiplayer ladder");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 2);
        add(jLabel3, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelGames;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JLabel jLabelRank;
    // End of variables declaration//GEN-END:variables
}
